package com.gurumades.jsonform.server;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;

import com.gurumades.jsonform.server.forms.Form;


public class Main {

	/**
	 * @param args
	 * @throws JAXBException 
	 */
	 @SuppressWarnings({ "unchecked", "deprecation" })
	public static void main(String[] args) throws JAXBException {
		
		JAXBContext jc = JAXBContext.newInstance("com.gurumades.jsonform.server.forms");
        
        Unmarshaller unmarshaller = jc.createUnmarshaller();
       
		JAXBElement<Form> o = (JAXBElement<Form>) unmarshaller.unmarshal(new File("war/WEB-INF/forms/publish_app.xml"));
        
        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
        mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
        mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
        
        try {
        	
			String jsonString = mapper.defaultPrettyPrintingWriter().writeValueAsString(o.getValue());
			System.out.println(jsonString);
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
